package toy.keli.edic.data

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import toy.keli.edic.data.config.BookConf
import toy.keli.edic.data.local.entity.CategoryEntity
import toy.keli.edic.data.model.Category
import toy.keli.edic.domain.model.WordModel
import toy.keli.edic.ui.bookmark.components.SearchResult
import toy.keli.edic.ui.bookmark.components.SearchType
import toy.keli.edic.ui.history.HistoryWords
import toy.keli.edic.ui.home.WordModelViewModel
import toy.keli.edic.ui.home.wGroups
import toy.keli.edic.ui.listenbook.ListenBookData
import toy.keli.edic.ui.main.extend.bgRun
import toy.keli.edic.util.ActivityRun
import toy.keli.edic.view.RichTextFont

/**
 * 预查看的默认数据
 */
class PreviewData {
    companion object{
        @Composable
        fun selectWordPage(){
            ActivityRun.context = LocalContext.current
            BookConf.setDefBook()
            BookConf.instance.initByData("章节01\nabc,about,after,ago\n\n章节02\nbefor,but")
            BookConf.words = listOf(
                WordModel(null,"abc","0",0,ch="abc"),
                WordModel(null,"about","0",0,ch="关于"),
                WordModel(null,"after","0",0,ch="之后"),
                WordModel(null,"ago","0",0,ch="之前")
            )
            BookConf.instance.size = 4
        }

        fun listenBookScreen(lbd: ListenBookData) {
            lbd.textToRead = """
    When so much has been written about Charles Strickland, it may seem unnecessary that I should write more. A painter's monument is his work. It is true I knew him more intimately than most: I met him first before ever he became a painter, and I saw him not infrequently during the difficult years he spent in Paris; but I do not suppose I should ever have set down my recollections if the hazards of the war had not taken me to Tahiti. There, as is notorious, he spent the last years of his life; and there I came across persons who were familiar with him. I find myself in a position to throw light on just that part of his tragic career which has remained most obscure. If they who believe in Strickland's greatness are right, the personal narratives of such as knew him in the flesh can hardly be superfluous. What would we not give for the reminiscences of someone who had been as intimately acquainted with El Greco as I was with Strickland?
    But I seek refuge in no such excuses. I forget who it was that recommended men for their soul's good to do each day two things they disliked: it was a wise man, and it is a precept that I have followed scrupulously; for every day I have got up and I have gone to bed. But there is in my nature a strain of asceticism, and I have subjected my flesh each week to a more severe mortification. I have never failed to read the Literary Supplement of The Times. It is a salutary discipline to consider the vast number of books that are written, the fair hopes with which their authors see them published, and the fate which awaits them. What chance is there that any book will make its way among that multitude? And the successful books are but the successes of a season. Heaven knows what pains the author has been at, what bitter experiences he has endured and what heartache suffered, to give some chance reader a few hours' relaxation or to while away the tedium of a journey. And if I may judge from the reviews, many of these books are well and carefully written; much thought has gone to their composition; to some even has been given the anxious labour of a lifetime. The moral I draw is that the writer should seek his reward in the pleasure of his work and in release from the burden of his thought; and, indifferent to aught else, care nothing for praise or censure, failure or success.
    """.split("\n")
            lbd.textToRead= listOf("0123456789","0 1 2 3 4 5 6 7 8 9 ","abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ");
            BookConf.setDefBook()
            RichTextFont.topAll = "the,a,of,or,to,and,in,that,with,an,for,is,by,as,on,from,having,be,who,i,not,was,at,used,it,are,one,which,any,they,into,small,something,being,you,person,especially,their,relating,my,can,has,act,this,have,its,someone,make,but,large,usually,out,made,two,time,we,when,up,manner,flowers,some,more,he,other,people,all,were,than,his,had,body,between,your,if,form,state,without,part,so,through,like,water,new,been,very,over,leaves,system,no,after,white,consisting,about,long,quality,another,plant,place,north,where,will,use,cause,often,said,light,states,american,work,united,group,tree,surface,her,them,do,order,way,there,only,back,me,such,various,together,America,resembling,down,many,several,genus,blood,number,unit,before,process,our,position,around,high,common,great,take,characterized,characteristic,area,food,point,plants,set,yellow,under,life,good,first,containing,money,head,during,red,whose,property,particular,most,sound,would,line,become,action,what,etc,off,world,move,each,get,color,things,give,same,end,side,air,fruit,different,she,put,power,study,short,right,force,skin,old,found,computer,certain,capable,hard,information,liquid,making,lacking,against,disease,him,language,also,tropical,material,control,law,family,given,name,substance,much,just,device,human,using,man,structure,parts,public,activity,caused,own,could,equal,game,change,marked,go,strong,black,acid,three,young,others,amount,shrub,military,edible,condition,away,perennial,government,wood,see,while,piece,open,metal,living,should,feeling,shape,word,european,paper,day,animal,little,ground,means,woman,fish,children,business,may,well,period,physical,eastern,degree,come,value,country,these,last,both,produced,central,land,south,effect,social,important,method,dark,because,known,building,words,green,instrument,either,animals,kind,how,face,now,cut,years,music,hand,low,along,house,trees,hair,play,thin,resulting,did,branch,less,herb,behavior,similar,left,written,space,does,then,cells,company,makes,too,oil,showing,toward,covered,development,year,free,car,ball,room,us,member,sexual,show,energy,party,natural,formed,based,those,able,single,lower,home,cell,full,support,designed,again,direction,tissue,even,bearing,soft,must,field,series,ship,school,near,few,eyes,drug,course,base,top,pressure,child,service,matter,within,type,trade,main,every,chemical,region,movement,treatment,southern,related,heavy,heart,called,above,hold,involving,city,size,subject,gas".split(",").toSet()
            RichTextFont.hAll = setOf("written","should","recommended")

        }

        @Composable
        fun defaultPage(): WordModelViewModel {
            ActivityRun.context = LocalContext.current
            BookConf.setDefBook()
            return WordModelViewModel.defaultModel
        }

        @Composable
        fun groupTools(): Category {
            ActivityRun.context = LocalContext.current
            BookConf.setDefBook()
            BookConf.instance.initByData("章节01\nabc,about,after,ago\n\n章节02\nbefor,but")
            wGroups.addAll(BookConf.chapters)
            BookConf.words = listOf(
                WordModel(null,"abc","0",0),
                WordModel(null,"about","0",0)
            )
            HistoryWords.apply{
                add(WordModel(null,"after","0",0))
                add(WordModel(null,"ago","0",0))
            }
            HistoryWords.menu()
            return Category(CategoryEntity("目录01"))
        }

        @Composable
        fun bookSearch(searchResult: SnapshotStateList<SearchResult>): Boolean {
            var init = remember { false }
            if( LocalInspectionMode.current && !init) {
                init= true
                ActivityRun.context = LocalContext.current
                BookConf.setDefBook()
                GlobalVal.wordViewModel = WordModelViewModel.defaultModel
                searchResult.clear()
                searchResult.addAll(
                    listOf(
                        SearchResult(SearchType.category, 1, "目录a", ""),
                        SearchResult(SearchType.article, 1, "book1", "aaabbbbccccc", line = 1),
                        SearchResult(SearchType.article, 2, "book2", "dddeeefff", line = 10),
                        SearchResult(SearchType.article, 3, "book3", "aaaaaaaaaaaaaaa",line=100),
                        SearchResult(SearchType.article, 4, "book4", "bbbbbbbbbbbbbbbb", line = 2),
                    )
                )
            }
            return true
        }
    }
}